Export module content to a excel template?

Hi!

 

I have programmed a Doors2Excel Exporter. This exporter uses always a new Excel instance with an empty worksheet.

 

Now, I would like to change this behaviour. I have programmed a GUI box with radio boxes which activates (or deactivates) a file selector. If the user deactivate the file selector, the user can't choose "any own Excel file" and the Doors2Excel Exporter should use the standard Excel Sheet which is destinated on a fixed path for every user.

 

I have a function called excelInit(Module current module). In my script code under this line I have marked the point of problem in capital letters. This script uses the library "ole.inc" from the IBM Doors Installation!

 

bool excelInit(Module currentModule)
{

    // Connect to excel only, if it is a module export or the first module from a folder export
    if(isExcelAlreadyStarted == false)
    {
        objExcel = connectToApp(cObjExcelApplication, (NLS_("Excel")))
    }
    
    
    if (null objExcel)
    {
        return false
    }
    
    
    makeVisible objExcel
    
    //THIS IS MY LOGIC TO DECIDE WHETHER THE RADIO BOX IS ACTIVATED/DEACTIVATED
    //Standard Excel spreadsheet, another Excel spreadsheet or a new Excel instance?
    if(get(templateChoice) == 0)   //If templateChoice = 0 the Radio Box for standard Excel template is chosen
    {
        //Use standard Excel spreadsheet (the Excel file in the "fixed path")

        //The compiler gives me failures especially for following three lines of code.
        clear(args)
        put(args, exportFileSelect)   //The content of the global variable exportFileSelect is the fixed path for every user.
        checkRes(oleMethod(objWorkbooks, cMethodOpen, args)
    }
    elseif(get(templateChoice) == 1)
    {
        //Use another Excel spreadsheet
    }
    else
    {
        //Open a new Excel instance with a empty Excel spreadsheet

        //This function should be already coded in the code under this line. Because I don't programmed this function not complete I don't find this.
    }
    
    
    // get workbooks collection
    checkRes(oleGet(objExcel, cPropertyWorkbooks, objWorkbooks))
    if (null objWorkbooks)
    {
        ack getExtMsg("String_Unable_to_get_workbooks_collection",NLSTEMP_("The export failed because the workbooks collection was not retrieved."))
        return false
    }
    //oleCloseAutoObject(objExcel)
    //oleCloseAutoObject(objWorkbooks)
    
    
    // add one Workbook
    if(isExcelAlreadyStarted == false)
    {
        checkRes(oleMethod(objWorkbooks, cMethodAdd))
        //oleCloseAutoObject(objWorkbooks)
    }
    
    
    // get active workbook
    checkRes(oleGet(objExcel, cPropertyActiveWorkbook, objWorkbook))
    if (null objWorkbook)
    {
        ack getExtMsg("String_Unable_to_get_active_workbook",NLSTEMP_("The export failed because the active workbook cannot be retrieved."))
        return false
    }
    //oleCloseAutoObject(objExcel)
    //oleCloseAutoObject(objWorkbook)
    
    
    // get active sheet
    checkRes(oleGet(objWorkbook, "Sheets", objSheet))
    if (null objSheet)
    {
        ack getExtMsg("String_Unable_to_get_active_sheet",NLSTEMP_("The export failed because the client cannot retrieve the active sheet."))
        return false
    }
    //oleCloseAutoObject(objWorkbook)
    //oleCloseAutoObject(objSheet)
    
    
    // add new sheet
    checkRes(oleMethod(objSheet, "Add"))
    if (null objSheet)
    {
        ack getExtMsg("String_Unable_to_add_a_new_sheet",NLSTEMP_("The export failed because the client cannot retrieve a new sheet."))
        return false
    }
    //oleCloseAutoObject(objSheet)
    
    
    // get active sheet
    checkRes(oleGet(objWorkbook, cPropertyActiveSheet, objSheet))
    if (null objSheet)
    {
        ack getExtMsg("String_Unable_to_get_active_sheet",NLSTEMP_("The export failed because the client cannot retrieve the active sheet."))
        return false
    }
    //oleCloseAutoObject(objWorkbook)
    //oleCloseAutoObject(objSheet)
    
    
    // Rename activated, current Worksheet
    string sheetName = name(currentModule)
    checkRes(olePut(objSheet, cPropertyName, sheetName))
    //oleCloseAutoObject(objSheet)
    
    
    // set "isExcelAlreadyStarted"-Flag to true, if first module is exported
    isExcelAlreadyStarted = true
    
    
    return true
}


tobi_mehrl - Wed Oct 14 09:21:11 EDT 2015

Re: Export module content to a excel template?
Jim Wetzel - Wed Oct 14 13:14:59 EDT 2015

I'm  neophyte with this code stuff but have had the same problem.  When you say "fixed path"  I wonder if it is really the same for everyone.  In your code I don't see if you are using an absolute fixed path (say to to a file share) or relative fixed path (my documents).   I don't remember how I got this from (Louie, Mathias, SmartDXL?)  But if you are trying to save to each users documents folder this should help. 

*/

Double slashes (\\) are necessary as a single slash and character is taken as an escape code.  
Double created a literal slash
*/

//set homepath to windows environment variable %HOMEPATH%
string homepath = getenv("HOMEPATH")
string ascfileName = "C:" homepath "\\My Documents\\datafile.csv"

 

              ...Jim

Re: Export module content to a excel template?
RamPalappalayam - Mon Oct 19 10:00:27 EDT 2015


Use the script from enhanced export to excel:

http://www.galactic-solutions.com/downloads/GalacticDownloadExcel.htm

 

hope this helps

 

Ram Palappalayam